Skip to content

Assert values of enum datasets and other tweaks#1743

Merged
axelboc merged 10 commits intomainfrom
bigint-prep
Feb 3, 2025
Merged

Assert values of enum datasets and other tweaks#1743
axelboc merged 10 commits intomainfrom
bigint-prep

Conversation

@axelboc
Copy link
Contributor

@axelboc axelboc commented Jan 27, 2025

A final mixed bag of changes ahead of supporting bigints (cf. list of commits).

if (isComplexType(type)) {
return createMatrixComplexFormatter(notation);
}
): (val: ScalarValue<PrintableType>) => string; // override distributivity of `ValueFormatter`
Copy link
Contributor Author

@axelboc axelboc Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ValueFormatter is now distributive: ValueFormatter<PrintableType> is now (val: string) => string | (val: number) => string | (val: number | boolean) => string | ... instead of (val: string | number | boolean | ...) => string.

This simplifies typing the formatter factories, like createNumericFormatter, formatBool, etc. and saves us from using the as keyword in a few places.

However, the consumers of getFormatter don't like this new distributive type; when the time comes to call it, the val parameter is inferred to never (because there's no possible intersection type). So I'm overriding the return value to remove the distributivity and get back to (val: string | number | boolean | ...) => string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a can of worms 😅

if (isComplexType(type)) {
return createMatrixComplexFormatter(notation);
}
): (val: ScalarValue<PrintableType>) => string; // override distributivity of `ValueFormatter`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a can of worms 😅

@axelboc axelboc merged commit d529403 into main Feb 3, 2025
8 checks passed
@axelboc axelboc deleted the bigint-prep branch February 3, 2025 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants